package com.sl.biz.modular.group.dao.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.group.dao.entity.GroupDO;
import com.sl.biz.modular.group.dao.mapper.GroupMapper;
import com.sl.biz.modular.group.dao.service.GroupDaoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class GroupDaoServiceImpl extends ServiceImpl<GroupMapper, GroupDO> implements GroupDaoService {
    @Override
    public Boolean add(GroupDO groupDO) {
        return super.save(groupDO);
    }

    @Override
    public GroupDO queryById(String id) {
        return super.getById(id);
    }

    @Override
    public List<GroupDO> queryByTreePath(String treePath) {
        LambdaQueryWrapper<GroupDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.likeRight(GroupDO::getTreePath, treePath);
        return super.list(lambdaQueryWrapper);
    }

    @Override
    public List<GroupDO> queryByRelationTypeCode(String relationTypeCode, String productId) {
        LambdaQueryWrapper<GroupDO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(GroupDO::getRelationTypeCode, relationTypeCode);
        lambdaQueryWrapper.eq(StrUtil.isNotBlank(productId), GroupDO::getProductId, productId);

        return super.list(lambdaQueryWrapper);
    }
}
